unit Map_P1;

interface

uses
  SysUtils, Classes, ADODB, DataEngine, Class_P1, Class_P2;

type
  TMap_P1 = class(TDataEngine)
  public
    FTableName: string;
  public
    function ReadDS(AADODst: TADODataSet): TBaseClass; override;
    function GetStrsIndex(ABaseClass: TBaseClass): string; override;

    function GetStrInsert: string; override;
    function GetStrUpdate: string; override;
    function GetStrDelete: string; override;
    procedure SetParameters(ABaseClass: TBaseClass); override;

    function GetNextZPDH(P2A: TP2): Integer;
  end;

implementation

{ TMap_P1 }

function TMap_P1.GetNextZPDH(P2A: TP2): Integer;
begin
  Result := GetNextID(FTableName, 'ZPDH', ' AND YUE = ' + IntToStr(P2A.YUE));
end;

function TMap_P1.GetStrDelete: string;
begin
  Result:='DELETE FROM ' + FTableName + ' WHERE YUE = :YUE'
    + ' AND LB = :LB'
    + ' AND PDH = :PDH'
    + ' AND BH = :BH';
end;

function TMap_P1.GetStrInsert: string;
begin
  Result:='INSERT INTO ' + FTableName
         +'(YUE, ZPDH, LB, PDH, BH, RI, ZY, KMH, WBZL, JD, JE'
         +', WBJE, SL, DZH, DZBZ, KHBM, BMBM, ZYBM, JSFSBM, YWBH'
         +', FDATE, CASHID, CURMONTH, EXCHRATE, UNITPRICE, PZXZ)'
         +' VALUES'
         +'(:YUE, :ZPDH, :LB, :PDH, :BH, :RI, :ZY, :KMH, :WBZL, :JD, :JE'
         +', :WBJE, :SL, :DZH, :DZBZ, :KHBM, :BMBM, :ZYBM, :JSFSBM, :YWBH'
         +', :FDATE, :CASHID, :CURMONTH, :EXCHRATE, :UNITPRICE, :PZXZ)';
end;

function TMap_P1.GetStrsIndex(ABaseClass: TBaseClass): string;
begin
  with TP1(ABaseClass) do
  begin
    Result := IntToStr(YUE) + '-' + IntToStr(PDH) + '-' + IntToStr(BH);
  end;
end;

function TMap_P1.GetStrUpdate: string;
begin
  Result := 'UPDATE ' + FTableName+ ' SET'
         +' ZPDH=:ZPDH,'
         +' RI=:RI,'
         +' ZY=:ZY,'
         +' KMH=:KMH,'
         +' WBZL=:WBZL,'
         +' JD=:JD,'
         +' JE=:JE,'
         +' WBJE=:WBJE,'
         +' SL=:SL,'
         +' DZH=:DZH,'
         +' DZBZ=:DZBZ,'
         +' KHBM=:KHBM,'
         +' BMBM=:BMBM,'
         +' ZYBM=:ZYBM,'
         +' JSFSBM=:JSFSBM,'
         +' YWBH=:YWBH,'
         +' FDATE=:FDATE,'
         +' CASHID=:CASHID,'
         +' CURMONTH=:CURMONTH,'
         +' EXCHRATE=:EXCHRATE,'
         +' UNITPRICE=:UNITPRICE,'
         +' PZXZ=:PZXZ'
         +' WHERE YUE=:YUE'
         +' AND LB=:LB'
         +' AND PDH=:PDH'
         +' AND BH=:BH';
end;

function TMap_P1.ReadDS(AADODst: TADODataSet): TBaseClass;
begin
  Result := TP1.Create;
  with TP1(Result) do
  begin
    YUE := AADODst.FieldByName('YUE').AsInteger;
    ZPDH := AADODst.FieldByName('ZPDH').AsInteger;
    LB := AADODst.FieldByName('LB').AsString;
    PDH := AADODst.FieldByName('PDH').AsInteger;
    BH := AADODst.FieldByName('BH').AsInteger;
    RI := AADODst.FieldByName('RI').AsInteger;
    ZY := AADODst.FieldByName('ZY').AsString;
    KMH := AADODst.FieldByName('KMH').AsString;
    WBZL := AADODst.FieldByName('WBZL').AsString;
    JD := AADODst.FieldByName('JD').AsString;
    JE := AADODst.FieldByName('JE').AsFloat;
    WBJE := AADODst.FieldByName('WBJE').AsFloat;
    SL := AADODst.FieldByName('SL').AsFloat;
    DZH := AADODst.FieldByName('DZH').AsString;
    DZBZ := AADODst.FieldByName('DZBZ').AsString;
    KHBM := AADODst.FieldByName('KHBM').AsString;
    BMBM := AADODst.FieldByName('BMBM').AsString;
    ZYBM := AADODst.FieldByName('ZYBM').AsString;
    JSFSBM := AADODst.FieldByName('JSFSBM').AsString;
    YWBH := AADODst.FieldByName('YWBH').AsString;
    FDATE := AADODst.FieldByName('FDATE').AsString;
    CASHID := AADODst.FieldByName('CASHID').AsString;
    CURMONTH := AADODst.FieldByName('CURMONTH').AsInteger;
    EXCHRATE := AADODst.FieldByName('EXCHRATE').AsFloat;
    UNITPRICE := AADODst.FieldByName('UNITPRICE').AsFloat;
    PZXZ := AADODst.FieldByName('PZXZ').AsString;
  end;
end;

procedure TMap_P1.SetParameters(ABaseClass: TBaseClass);
var
  ObjA: TP1;
begin
  ObjA := TP1(ABaseClass);
  with FADOCmd.Parameters do
  begin
    case FOpType of
      otAdd, otEdit:
      begin
        ParamByName('YUE').Value := ObjA.YUE;
        ParamByName('ZPDH').Value := ObjA.ZPDH;
        ParamByName('LB').Value := ObjA.LB;
        ParamByName('PDH').Value := ObjA.PDH;
        ParamByName('BH').Value := ObjA.BH;
        ParamByName('RI').Value := ObjA.RI;
        ParamByName('ZY').Value := ObjA.ZY;
        ParamByName('KMH').Value := ObjA.KMH;
        ParamByName('WBZL').Value := ObjA.WBZL;
        ParamByName('JD').Value := ObjA.JD;
        ParamByName('JE').Value := ObjA.JE;
        ParamByName('WBJE').Value := ObjA.WBJE;
        ParamByName('SL').Value := ObjA.SL;
        ParamByName('DZH').Value := ObjA.DZH;
        ParamByName('DZBZ').Value := ObjA.DZBZ;
        ParamByName('KHBM').Value := ObjA.KHBM;
        ParamByName('BMBM').Value := ObjA.BMBM;
        ParamByName('ZYBM').Value := ObjA.ZYBM;
        ParamByName('JSFSBM').Value := ObjA.JSFSBM;
        ParamByName('YWBH').Value := ObjA.YWBH;
        ParamByName('FDATE').Value := ObjA.FDATE;
        ParamByName('CASHID').Value := ObjA.CASHID;
        ParamByName('CURMONTH').Value := ObjA.CURMONTH;
        ParamByName('EXCHRATE').Value := ObjA.EXCHRATE;
        ParamByName('UNITPRICE').Value := ObjA.UNITPRICE;
        ParamByName('PZXZ').Value := ObjA.PZXZ;
      end;
      otDel:
      begin
        ParamByName('YUE').Value := ObjA.YUE;
        ParamByName('LB').Value := ObjA.LB;
        ParamByName('PDH').Value := ObjA.PDH;
        ParamByName('BH').Value := ObjA.BH;
      end;  
    end;
  end;
end;

end.
